package com.sdw.soft.core.utils.photo;

import java.awt.AWTException;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Robot;
import java.awt.Toolkit;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 * @author shangyd
 * @date 2015年6月23日 下午2:05:25
 **/
public class PhotoDeal {

	private String fileName = "D:/photo";
	private String format = "jpg";
	public static void main(String[] args) {
		new PhotoDeal().snapShot();
	}
	public void snapShot() {
	    try {
	        Dimension dimension = Toolkit.getDefaultToolkit().getScreenSize();
	        BufferedImage screenshot = (new Robot()).createScreenCapture(
	                new Rectangle(0, 0, (int) dimension.getWidth(), (int) dimension.getHeight()));

	        String fileName = this.fileName + "." + this.format;
	        File file = new File(fileName);
	        File parentFile = file.getParentFile();
	        if (parentFile != null && !parentFile.exists()) {
	            parentFile.mkdir();
	        }

	        ImageIO.write(screenshot, format, file);
	    } catch (AWTException e) {
	        e.printStackTrace();
	    } catch (IOException e) {
	        e.printStackTrace();
	    }
	}

}
